package offer;

/**
 * @author SSK
 * 数字在排序数组中出现的次数
 */
public class T38 {
    public int GetNumberOfK(int [] array , int k) {
        return serach(array,k+0.5)-serach(array,k-0.5);
    }
    public int serach(int[] array , double k) {
        int l = 0;
        int r = array.length-1;
        while (l<=r) {
            int mid =(l+r)>>1;
            //System.out.println(mid+" "+l+" "+r+" "+array[mid]+" "+k);
            if (array[mid]<k){
                l=mid+1;
            }else {
                r=mid-1;
            }
        }
        System.out.println(l);
        return l;
    }

    public static void main(String[] args) {
        System.out.println(new T38().GetNumberOfK(new int[]{1,2,3,3,3,3,4,5},3));
    }
}
